﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>消息实体</title>
    <!--SQL编辑器-->
    <link href="../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" />
    <link href="../../Scripts/CodeMirror/lib/codemirror.css" rel="stylesheet" />
    <link href="../../Scripts/CodeMirror/addon/hint/show-hint.css" rel="stylesheet" />
    <script src="../../Scripts/CodeMirror/lib/codemirror.js"></script>
    <script src="../../Scripts/CodeMirror/addon/edit/matchbrackets.js"></script>
    <script src="../../Scripts/CodeMirror/mode/sql/sql.js"></script>
    <script src="../../Scripts/CodeMirror/addon/hint/show-hint.js"></script>
    <script src="../../Scripts/CodeMirror/addon/hint/sql-hint.js"></script>

    <link href="../../Style/skin/css/Default.css" rel="stylesheet" />
    <link href="../../Style/skin/adminfont/iconfont.css" rel="stylesheet" />
    <link href="../../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />

    <script src="../../Scripts/LoadSql.js"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Comm/Gener.js"></script>
    <base target="_self" />
    <script src="../Admin.js"></script>

    <script type="text/javascript">
        function Esc() {
            if (event.keyCode == 27)
                window.close();
            return true;
        }
        function WinOpen(url, name) {
            window.open(url, name, 'height=600, width=800, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');
            //window.open(url, 'xx');
        }
        /*隐藏与显示.*/
        function ShowHidden(ctrlID) {

            var ctrl = document.getElementById(ctrlID);
            if (ctrl.style.display == "block") {
                ctrl.style.display = 'none';
            } else {
                ctrl.style.display = 'block';
            }
        }
    </script>
    <script type="text/javascript" language="javascript">
        //页面启动函数.
        $(function () {

            var fk_event = GetQueryString("FK_Event");
            if (fk_event == "NodeWarning") {
                $("#NodeOverDue").hide();
            } else if (fk_event == "NodeOverDue") {
                $("#NodeWarn").hide();
            } else {
                $("#NodeOverDue").hide();
                $("#NodeWarn").hide();
            }
            if (fk_event == "CCAfter" || fk_event == "PressAfter") {
                $("#NodeOverDue").hide();
                $("#NodeWarn").hide();
                $("#RB_SMS_3").parent().parent().hide();
                $("#RB_SMS_4").parent().parent().hide();
                $("#RB_SMS_5").parent().parent().hide();
            }
            InitPage();

        });

        //初始化数据.
        function InitPage() {
            var fk_event = GetQueryString("FK_Event");
            // 设置标签
            $("#eventtype").html(fk_event);
            $("label[for='RB_Email_1']").html(_GetText(GetQueryString("FK_Event")));
            $("label[for='RB_SMS_1']").html(_GetText(GetQueryString("FK_Event")));

            //初始化 01 02 03
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_AttrNode");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("PushMsgEntity_Init");

            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            data = JSON.parse(data);
            var frmfields = data.FrmFields;
            var nodes = data.Nodes;
            var en = data.PushMsgEntity[0];

            //01.填充下拉
            for (var i = 0, len = frmfields.length; i < len; i++) {
                var f = frmfields[i];
                var oVal = f.KeyOfEn;
                var oText = f.KeyOfEn + "  ; " + f.Name;
                $("#DDL_SMS_Fields").append("<option value='" + oVal + "' >" + oText + "</option>");
                $("#DDL_Email_Fields").append("<option value='" + oVal + "' >" + oText + "</option>");
            }

            //02.节点列表
            for (i = 0, len = nodes.length; i < len; i++) {
                var n = nodes[i];
                $("#SMS_Nodes").append("<label><input id='CB_SMS_" + n.NodeID + "' type='checkbox' name='CB_SMS_" + n.NodeID + "' />" + n.Name + "</label>");
                $("#Email_Nodes").append("<label><input id='CB_Email_" + n.NodeID + "' type='checkbox' name='CB_Email_" + n.NodeID + "' />" + n.Name + "</label>");
            }

            //03.实体初始化 （如果有）
            if (en.MyPK != "") {
                $("input:radio[name='RB_SMS']").eq(en.SMSPushWay).attr("checked", true);
                $("input:radio[name='RB_Email']").eq(en.MailPushWay).attr("checked", true);
                $("#DDL_SMS_Fields").val(en.SMSField);
                $("#DDL_Email_Fields").val(en.MailAddress);
                $("#TB_SMS").val(en.SMSDoc);
                $("#TB_Title").val(en.MailTitle);

                var smsnodes = en.SMSNodes;
                var mailnodes = en.MailNodes;
                if (smsnodes != "") {
                    var ns = smsnodes.split(",");
                    for (i = 0, len = ns.length; i < len; i++) {
                        if (ns[i] != "") {
                            document.getElementById("CB_SMS_" + ns[i]).checked = true;
                        }
                    }
                }
                if (mailnodes != "") {
                    var ns = mailnodes.split(",");
                    for (i = 0, len = ns.length; i < len; i++) {
                        if (ns[i] != "") {
                            document.getElementById("CB_Email_" + ns[i]).checked = true;
                        }
                    }
                }

                // 短消息发送形式
                var smsPushModel = en.SMSPushModel;
                if (smsPushModel != "") {
                    var pushModels = smsPushModel.split(",");
                    for (i = 0, len = pushModels.length; i < len; i++) {
                        if (pushModels[i] != "") {
                            document.getElementById("CB_SMSPushModel_" + pushModels[i]).checked = true;
                        }
                    }
                }

            }
            else {
                $("#DDL_SMS_Fields option:first").attr("selected", "selected");
                $("#DDL_Email_Fields option:first").attr("selected", "selected");
            }

            if (fk_event == "NodeWarning") {
                var noticeType = GetPara(en.AtPara, "NoticeType");
                document.getElementById("RB_NoticeType_" + noticeType).checked = true;
                var hour = GetPara(en.AtPara, "NoticeHour");
                $("#TB_NoticeHour").val(hour);
            } else if (fk_event == "NodeOverDue") {
                var noticeType = GetPara(en.AtPara, "NoticeType");
                document.getElementById("RB_NoticeType_" + noticeType).checked = true;

                var day = GetPara(en.AtPara, "NoticeDay");
                $("#TB_NoticeDay").val(day);
            }
            $("#TB_SQL").val(en.BySQL);
            $("#TB_Emps").val(en.ByEmps);
        }

        //页面初始化调用
        function _GetText(EventListNode) {

            var ret = {
                "WorkArrive": "发送给当前节点的所有处理人",
                "SendSuccess": "发送给下一个节点的所有接受人",
                "ReturnAfter": "发送给被退回的节点处理人",
                "UndoneAfter": "撤销工作后通知的节点接受人",
                "ShitAfter": "发送给被移交的节点接受人",
                "CCAfter": "发送给被抄送的人",
                "PressAfter": "发送给被催办的人",
                "FlowOverAfter": "流程结束通知的所有流程的参与人",
                "AfterFlowDel": "流程删除后通知所有流程的参与人",
                "NodeWarning": "发送给当前节点的所有处理人",
                "NodeOverDue": "发送给当前节点的所有处理人",
            };
            return ret[EventListNode];

        }

        function Save() {
            var fk_event = GetQueryString("FK_Event");
            if (fk_event == "NodeWarning" || fk_event == "NodeOverDue") {
                var val = $('input:radio[name="RB_NoticeType"]:checked').val();
                if (val == null) {
                    if (fk_event == "NodeWarning")
                        alert("请选择预警提醒方式");
                    if (fk_event == "NodeOverDue")
                        alert("请选择逾期提醒方式");
                    return;
                }
            }
            //获取短消息发送设置
            var pushModels = document.getElementsByName('CB_SMSPushModel');
            var pushModel = '';
            for (var i = 0; i < pushModels.length; i++) {
                if (pushModels[i].checked)
                    pushModel += pushModels[i].value + ','; //如果选中，将value添加到变量s中
            }
            //初始化 01 02 03
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_AttrNode");
            handler.AddUrlData();
            handler.AddFormData();
            handler.AddPara("PushModel", pushModel);
            var data = handler.DoMethodReturnString("PushMsg_Save");
            if (data.indexOf('err@') >= 0) {
                alert(data);
                return;
            }

            alert(data);
            Back();
        }

        function Back() {
            var url = '';
            url = 'PushMessage.htm?FK_Node=' + GetQueryString('FK_Node') + '&FK_Flow=' + GetQueryString('FK_Flow') + '&m' + Math.random();
            window.location.href = url;
        }

    </script>
</head>
<body onkeypress="Esc();">
    <div class="container-full">
        <div class="attrnode-bar-header">
            <span class="pull-right">

                <button id="Btn_Save" name="Btn_Save" onclick="Save();">保存</button>
                <!--<button id="Btn_New" name="Btn_New" onclick="SaveAndNew();">保存并新建</button>-->
                <button id="Btn_Back" name="Btn_Back" onclick="Back();">返回</button>

            </span>
            <strong>消息实体</strong>
        </div>
        <form id="cc">

            <div style="position:relative;top:10px; margin: 8px">
                <table style="width:100%;" class="table">

                    <tr>
                        <td colspan="2">
                            <input id="RB_SMS_0" type="radio" name="RB_SMS" value="0"
                                   checked="checked" /><label for="RB_SMS_0">不发送</label>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <input id="RB_SMS_1" type="radio" name="RB_SMS" value="1" /><label for="RB_SMS_1"></label>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 200px;">
                            <input id="RB_SMS_2" type="radio" name="RB_SMS" value="2" /><label for="RB_SMS_2">表单上的字段作为接受对象</label>
                        </td>
                        <td>
                            <select name="DDL_SMS_Fields" id="DDL_SMS_Fields" class="frmfields"></select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input id="RB_SMS_3" type="radio" name="RB_SMS" value="3" /><label for="RB_SMS_3">其他节点的处理人</label>
                        </td>
                        <td id="SMS_Nodes"></td>
                    </tr>

                    <tr>
                        <td>
                            <input id="RB_SMS_4" type="radio" name="RB_SMS" value="4" /><label for="RB_SMS_4">按照SQL计算</label>
                        </td>
                        <td>
                            <textarea id="TB_SQL" name="TB_SQL"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input id="RB_SMS_5" type="radio" name="RB_SMS" value="5" /><label for="RB_SMS_5">发给指定的人</label>
                        </td>
                        <td>
                            <textarea id="TB_Emps" name="TB_Emps"></textarea>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <input id="RB_SMS_6" type="radio" name="RB_SMS" value="6" /><label for="RB_SMS_6">开始节点的发起人</label>
                        </td>
                        <td>
                        </td>
                    </tr>



                    <tr>
                        <td>
                            <label>发送形式</label>
                        </td>
                        <td>
                            <label><input id='CB_SMSPushModel_Email' type='checkbox' name='CB_SMSPushModel' value='Email' />邮件</label>
                            <label><input id='CB_SMSPushModel_CCMsg' type='checkbox' name='CB_SMSPushModel' value='CCMsg' />站内消息</label>
                            <label><input id='CB_SMSPushModel_SMS' type='checkbox' name='CB_SMSPushModel' value='SMS' />短信</label>
                            <label><input id='CB_SMSPushModel_DingDing' type='checkbox' name='CB_SMSPushModel' value='DingDing' />钉钉</label>
                            <label><input id='CB_SMSPushModel_WeiXin' type='checkbox' name='CB_SMSPushModel' value='WeiXin' />微信</label>
                            <label><input id='CB_SMSPushModel_WS' type='checkbox' name='CB_SMSPushModel' value='WS' />WebServices </label>
                            <a href="javascript:alert('1. for: .net ccbpm会把信息写入到 \datauser\PortalInterface.asmx \t\n2. for java:请参考 java相关代码. ');"><img src="../../Img/Btn/Help.gif" />设置帮助</a>
                        </td>
                    </tr>
                    <tr id="NodeWarn">
                        <td>
                            <label id="NoticeLabel">预警提醒方式</label>
                        </td>
                        <td>
                            <label><input id='RB_NoticeType_0' type='radio' name='RB_NoticeType' value='0' />每天提醒一次</label><br />

                            <label><input id='RB_NoticeType_1' type='radio' name='RB_NoticeType' value='1' />按时间段提醒</label>
                            &nbsp;&nbsp;&nbsp;&nbsp;提前<input type="text" id="TB_NoticeHour" name="TB_NoticeHour" />小时发送一次消息
                        </td>
                    </tr>

                    <tr id="NodeOverDue">
                        <td>
                            <label>逾期提醒方式</label>
                        </td>
                        <td>
                            <label><input id='RB_NoticeType_0' type='radio' name='RB_NoticeType' value='0' />每天提醒一次</label><br />

                            <label><input id='RB_NoticeType_1' type='radio' name='RB_NoticeType' value='1' />按时间段提醒</label>
                            &nbsp;&nbsp;&nbsp;&nbsp;逾期<input type="text" id="TB_NoticeDay" name="TB_NoticeDay" />天发送一次消息
                        </td>
                    </tr>


                    <tr>
                        <td>
                            <label>邮件标题</label>
                        </td>
                        <td>
                            <input type="text" id="TB_Title" name="TB_Title" style="width:97%;" />
                        </td>
                    </tr>

                    <tr>
                        <td colspan="2">
                            <fieldset style="border: 0px;">
                                <legend><a href="javascript:ShowHidden('sms')">消息发送内容模版:</a></legend>
                                <div id="sms" style="display: none; color: Gray">
                                    <ul>
                                        <li>cc会根据不同的事件设置不同的信息模版。</li>
                                        <li>这些模版都是标准的提示，如果您要需要个性化的提示请修改该模版。</li>
                                        <li>该参数支持cc表达式。</li>
                                        <li>您可以使用@符号来编写您所需要的内容。</li>
                                        <li>对于信息提示有两个系统参数分别是{Title}流程标题， {URL} 打开流程的连接。</li>
                                        <li>cc在生成消息的时候会根据模版把信息替换下来，发送给用户。</li>
                                        <li>最新格式的cc字段表达式为: <font color="red">@+字段名+分号</font> 比如 @QingJiaLeiXing; </li>
                                    </ul>
                                </div>
                            </fieldset>
                            <textarea name="TB_SMS" rows="3" cols="20" id="TB_SMS"
                                      style="width: 95%;">
有新工作{{Title}}需要您处理, 发送人:@WebUser.No, @WebUser.Name,打开{Url} .</textarea>
                        </td>
                    </tr>
                </table>
            </div>

            <fieldset>
                <legend> 帮助 </legend>
                <ul>
                    <li>消息实体用于定义当前的事件触发后对外发送消息.</li>
                    <li>一个事件可以定义多个消息实体,这样就可以定义不同的人群，消息模版可以不一样.</li>

                </ul>
            </fieldset>
        </form>
    </div>
</body>
</html>
